// pages/order/arOrder/arOrder.js
const app = getApp();
const util = require('../../../utils/util.js');

Page({

  /**
   * 页面的初始数据
   */
  data: {
    quotationId: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    app.request('/Order/QuotationDetailForAnnualVerificatio', 'GET', { annualVerificatioId: options.quotationId }, res => {
      this.setData({
        quotationId: options.quotationId,
        carPhoto: res.quotationCarModel.carPhoto,
        licencePlate: res.quotationCarModel.licencePlate,
        quotationNumber: res.annualVerificationQuotation.quotationNumber,
        createTime: util.formatTime(res.annualVerificationQuotation.createTime),
        takeCarWayText: res.annualVerificationQuotation.takeCarWay === 1 ? '自行驾车到指定地点' : '专人上门接车',
        takeCarAddress: res.annualVerificationQuotation.takeCarAddress,
        buyCompulsoryWayText: res.annualVerificationQuotation.buyCompulsoryWay === 1 ? '自行购买' : '平台购买',
        contactsName: res.annualVerificationQuotation.contactsName,
        contactsPhoneNumber: res.annualVerificationQuotation.contactsPhoneNumber,
        annualVerificationQuotationDetail: res.annualVerificationQuotationDetail,
        quotationStatus: res.annualVerificationQuotation.quotationStatus,
        quotationStatusName: res.annualVerificationQuotation.quotationStatusName
      });
    });
  },
  /**
   * 点击取消报价单
   */
  cancelFn() {
    wx.showModal({
      title: '取消报价单',
      content: '确定要取消此年审报价单吗？',
      success: res => {
        if (res.confirm) {
          app.request('/Order/CancelQuotation', 'DELETE', {
            userId: app.globalData.userId,
            quotationType: 0,
            quotationId: this.data.quotationId
          }, res => {
            wx.showToast({ title: '取消成功', icon: 'none', duration: 2000 });
            var pages = getCurrentPages(); // 当前页面
            var beforePage = pages[pages.length - 2]; // 前一个页面
            beforePage.getData('update');
            wx.navigateBack({delta: 1});
          });
        }
      }
    });
  }
})